package com.boyu.backend;

import com.boyu.common.*;
import com.boyu.common.model.Column;
import com.boyu.common.showmodel.ShowColumn;

import java.util.List;

/**
 * IndexController
 */
public class _ColumnController extends BaseController {


    public void index() {
        List<ShowColumn> showColumns = ColumnLogic.getInstance().columnLoad();
        setSessionAttr(SystemConst.ADMIN_COLUMN, showColumns);
        render(INDEX_HTML);
    }

    public void add() {
        int parentId = getParaToInt(PARENT_ID, -1);
        setAttr(PARENT_ID, parentId);
        render(ADD_HTML);
    }

    public void del() {
        Column.dao.deleteById(getParId());
        redirect(INDEX);
    }

    public void edit() {
        long id = getParaToLong(ID);
        Column byId = Column.dao.findById(id);
        setAttr(COLUMN, byId);
        render(EDIT_HTML);
    }

    public void save() {
        Column model = getModel(Column.class, "");
        if (model.getId() != null) {
            model.update();
        } else {
            model.save();
        }
        redirect(INDEX);
    }
}





